import RandTool from "../../common/tool/RandTool";
import ContextPool from "../../common/tool/context/ContextPool";
import GameSnake from "../GameSnake";
import BodyBase from "./BodyBase";
const { ccclass, property } = cc._decorator;
@ccclass
export default class BodyFood extends BodyBase {
    @property(cc.Label)
    public LabelNumber: cc.Label = null;


    protected mAddFood: number = 0;
    public get AddFood(): number {
        return this.mAddFood;
    }

    public init(content: ContextPool): boolean {
        super.init(content);
        this.mAddFood = RandTool.RandIncludeAll(1, 5);
        this.refershFood();
        return true;
    }

    public refershFood() {
        this.LabelNumber.string = this.mAddFood.toString();
    }

    public onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider): void {
        let snake = this.getContext(GameSnake);
        snake.eatFood(this.mAddFood);

        this.node.destroy();
        console.log('-------------', 'destory~~~~~');
        cc.systemEvent.emit('snake-block-die');
    }
}
